package com.wangsd.web.shop.service;

import com.gitee.fastmybatis.core.query.Query;
import com.wangsd.web.shop.entity.ActivityDetail;
import com.wangsd.web.shop.mapper.ActivityDetailMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ActivityDetailService {
    @Resource
    private ActivityDetailMapper mapper;

    @Transactional
    public void save(Long activityId, List<ActivityDetail> details) {
        mapper.deleteByQuery(new Query().eq("activity_id", activityId));
        List<ActivityDetail> list = new ArrayList();
        for (ActivityDetail detail : details) {
            detail.setActivityId(activityId);
            list.add(detail);
        }
        mapper.saveBatch(list);
    }

    public List<ActivityDetail> selectByActivityId(Long activityId) {
        return mapper.listByColumn("activity_id", activityId);
    }
}
